//
// Created by juno on 2021/9/9.
//
#include <stdio.h>
#include <ctype.h>
#include "common.h"

int gen_token(char **res)
{
    FILE *fp;
    char buf[128] = {0};
    size_t len = 0;

    fp = fopen("/proc/sys/kernel/random/uuid", "r");

    if (!fp)
        return -1;

    len = fread(buf, 1, sizeof(buf) -1, fp);

    if (len > 0)
    {
        char out[128] = {0};
        int count = 0;
        for (int i = 0; i < len; i++)
        {
            if (!isxdigit(buf[i]))
                continue;
            out[count] = buf[i];
            count += 1;
        }
        *res = strdup(out);
        return count;
    }
    return -1;
}

void destroy_message(void *data)
{
    struct msg *msg = data;
    if (msg)
        if (msg->payload)
            free(msg->payload);

}
